<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
<head>
    <title>套餐设置</title>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
    <a href="javascript:history.go(-1);" class="top_fh">套餐设置</a>
</header>
<!-- header end -->

<div class="page home_page">
    <div class="home_tcsetinner">
        <form id="addform">
            <ul>
            <c:forEach items="${discountList}" var="discount">
                <li ${discount.flag==1?"class='cur'":""}>${discount.discountname}<input type="hidden" name="discountIds" ${discount.flag==1?"":"disabled='disabled'"} value="${discount.discountid}" /></li>
            </c:forEach>
            </ul>
        </form>
        <div class="tcse_button"><a href="JavaScript:;" id="saveBtn">保存</a></div>
    </div>
</div>
<script type="application/javascript">
    function View(){
        var that = this;

        that.events = [
            { sel : '#addform ul li', act : 'click', func : 'clickDiscount' },
            { sel : '#saveBtn', act : 'click', func : 'saveSub' }
        ];

        that.clickDiscount = function(){
            if($(this).hasClass('cur')){
                $(this).removeClass('cur');
                $(this).children("input").attr("disabled","disabled");
            }else{
                $(this).addClass('cur');
                $(this).children("input").removeAttr("disabled","disabled");
            }
        };

        that.saveSub = function(){
            $.ajax({
                url:'${basePath}wechat/operate/device/${deviceId}/editDiscount',
                type : 'POST',
                data : $("#addform").serialize(),
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        window.location = "${basePath}wechat/operate/device/${deviceId}/discountView";
                    }else{
                        alert(ret.info);
                    }
                }
            });
        };

        EventHandler.call(that, that.events);

        return that;
    }

    var view;

    $(function(){
        inherit(View, EventHandler);
        view = new View();
    });
</script>
</body>
</html>